<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('系统风控设置')" />
</head>
<body>
<div class="main-content">
	<form id="form-control-edit" class="form-horizontal" style="width: 800px" th:object="${sysControl}">
		<input name="controlId"  type="hidden"  th:field="*{controlId}" />
		<input name="relationId"  type="hidden"  th:field="*{relationId}" />
		<h4 class="form-header h4">风控规则</h4>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">单笔最小金额:</label>
					<div class="col-sm-8">
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white subSize" style="height: 31px;"><i class="fa fa-chevron-left"></i>
							</button>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<input type="text" id="minBalance" name="minBalance" class="form-control" style="width: 120px;text-align: center" th:field="*{minBalance}">
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white addSize" style="height: 31px;"><i class="fa fa-chevron-right"></i>
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">单笔最大金额:</label>
					<div class="col-sm-8">
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white subSize" style="height: 31px;"><i class="fa fa-chevron-left"></i>
							</button>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<input type="text" id="maxBalance" name="maxBalance" class="form-control" style="width: 120px;text-align: center" th:field="*{maxBalance}" required>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white addSize" style="height: 31px;"><i class="fa fa-chevron-right"></i>
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">今日总金额:</label>
					<div class="col-sm-8">
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white subSize" style="height: 31px;"><i class="fa fa-chevron-left"></i>
							</button>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<input type="text" id="todayBalance" name="todayBalance" class="form-control" style="width: 120px;text-align: center" th:field="*{todayBalance}" required>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white addSize" style="height: 31px;"><i class="fa fa-chevron-right"></i>
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">交易时间:</label>
					<div class="col-sm-8">
						<div class="input-daterange input-group">
							<input type="text" class="input-sm form-control" id="controlStartTime" name="controlStartTime" placeholder="HH:mm:ss" th:field="*{startTime}">
							<span class="input-group-addon">到</span>
							<input type="text" class="input-sm form-control" id="controlEndTime" name="controlEndTime" placeholder="HH:mm:ss" th:field="*{endTime}">
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">单位时间限制:</label>
					<div class="col-sm-8">
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white subSize" style="height: 31px;"><i class="fa fa-chevron-left"></i>
							</button>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<input type="text" id="timeRange" name="timeRange" class="form-control" style="width: 120px;text-align: center" th:field="*{timeRange}" required>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white addSize" style="height: 31px;"><i class="fa fa-chevron-right"></i>
							</button>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<select id="timeUnit" name="timeUnit" class="form-control m-b" th:with="type=${@dict.getType('sys_date_type')}">
								<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue} eq *{timeUnit}"></option>
							</select>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">单位时间次数:</label>
					<div class="col-sm-8">
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white subSize" style="height: 31px;"><i class="fa fa-chevron-left"></i>
							</button>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<input type="text" id="timeSize" name="timeSize" class="form-control" style="width: 120px;text-align: center" th:field="*{timeSize}" required>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white addSize" style="height: 31px;"><i class="fa fa-chevron-right"></i>
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">单位时间金额:</label>
					<div class="col-sm-8">
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white subSize" style="height: 31px;"><i class="fa fa-chevron-left"></i>
							</button>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<input type="text" id="timeBalance" name="timeBalance" class="form-control" style="width: 120px;text-align: center" th:field="*{timeBalance}" required>
						</div>
						<div class="input-group" style="display: inline-block;float: left">
							<button type="button" class="btn btn-white addSize" style="height: 31px;"><i class="fa fa-chevron-right"></i>
							</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-sm-6">
				<div class="form-group">
					<label class="col-sm-4 control-label">风控状态：</label>
					<div class="col-sm-8">
						<label class="toggle-switch switch-solid">
							<input type="checkbox" id="controlStatus" th:field="*{controlStatusBn}">
							<span></span>
						</label>
					</div>
				</div>
			</div>
		</div>

	</form>
</div>

<!--<div class="row" style="width: 800px">-->
<!--	<div class="col-sm-offset-2 col-sm-10">-->
<!--		<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;-->
<!--		<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>-->
<!--	</div>-->
<!--</div>-->
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: datetimepicker-js" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('system:control:edit')}]];
		// var removeFlag = [[${@permission.hasPermi('system:control:remove')}]];
		var prefix = ctx + "system/channel";


		$(function() {
		    var options = {
				// $.table.init(options);
			}
			layui.use('laydate', function(){
				var laydate = layui.laydate;

				laydate.render({
					elem: '#controlStartTime',
					type: 'time',
					format: 'HH:mm:ss',
					// ready: formatminutes
				});

				laydate.render({
					elem: '#controlEndTime',
					type: 'time',
					format: 'HH:mm:ss',
					// ready: formatminutes
				});
			});

		});

		//layui清空秒
		function formatminutes(date){
			var aa = $(".laydate-time-list li ol")[1];
			var showtime = $($(".laydate-time-list li ol")[1]).find("li");
			for (var i = 0; i < showtime.length; i++) {
				var t00 = showtime[i].innerText;
				if (t00 != "00" && t00 != "10" && t00 != "20" && t00 != "30" && t00 != "40" && t00 != "50") {
					showtime[i].hidden = true;
				}
			}
			$(".laydate-time-list").children().each(function(){
				console.log($(this))
				if ($(this).find("p").html()=='秒'){
					$(this).remove();
				}
			});
			$($(".laydate-time-list li ol")[2]).find("li").remove();  //清空秒
		}

		$(".addSize").click(function(){
			let number = $(this).parents().prev().children("input").val();
			number = parseInt(number);
			if (!Number.isInteger(number)) {
				$.modal.alertError("请输入正确的数字类型");
				return;
			}
			$(this).parents().prev().children("input").val(number+1);
		});

		$(".subSize").click(function(){
			let number = $(this).parents().next().children("input").val();
			number = parseInt(number);
			if (!Number.isInteger(number)) {
				$.modal.alertError("请输入正确的数字类型");
				return;
			}
			if(number>0){
				$(this).parents().next().children("input").val(number-1);
			}
		});

		//保存表单
		function submitHandler(){
			//验证数字组
			var checkNumberArrays = new Array();
			checkNumberArrays.push("minBalance");
			checkNumberArrays.push("maxBalance");
			checkNumberArrays.push("todayBalance");
			checkNumberArrays.push("timeRange");
			checkNumberArrays.push("timeSize");
			checkNumberArrays.push("timeBalance");
			//验证日期组
			var checkDateArrays = new Array();
			checkDateArrays.push("controlStartTime");
			checkDateArrays.push("controlEndTime");
			//遍历验证数字
			for (let i = 0; i < checkNumberArrays.length; i++) {
				if(!checkNumberRule(checkNumberArrays[i])){
					return false;
				}
			}
			//遍历验证日期
			for (let i = 0; i < checkDateArrays.length; i++) {
				if(!checkDateRule(checkDateArrays[i])){
					return false;
				}
			}
			var data = $("#form-control-edit").serializeArray();
			var status = $("input[id='controlStatus']").is(':checked') == true ? 0 : 1;
			data.push({"name": "controlStatus", "value": status});
			$.operate.post(prefix+"/editChannelControl",data)
		}

		function checkNumberRule(data) {
			let number = $("#"+data+"").val();
			number = parseInt(number);
			if (!Number.isInteger(number)) {
				var pointOut = $("#"+data+"").parents().parents().parents().find("label").html();
				$.modal.alert(pointOut+"->必须为数字类型");
				return false;
			}
			return true;
		}
		function checkDateRule(data) {
			let checkDate = $("#"+data+"").val();
			let a = checkDate.match(/^(\d{1,2}):(\d{1,2}):(\d{1,2})$/);
			if (!a || a[1] > 24 || a[2] > 60 || a[3] > 60) {
				$.modal.alertError("请输入正确的时间格式");
				return false;
			}
			return true;
		}

	</script>
</body>
</html>